home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Learn C++ (CodeWarrior)
/
Chap 04.08 - inline
/
inline.cp
< prev
next >
Wrap
Text File
|
1995-10-20
|
530b
|
34 lines
#include <iostream.h>
inline long power( short base, short exponent );
int main()
{
cout << "power( 2, 3 ): " <<
power( 2, 3 ) << "\n";
cout << "power( 3, 6 ): " <<
power( 3, 6 ) << "\n";
cout << "power( 5, 0 ): " <<
power( 2, 0 ) << "\n";
cout << "power( -3, 4 ): " <<
power( -3, 4 ) << "\n";
return 0;
}
inline long power( short base, short exponent )
{
long product = 1;
short i;
if ( exponent < 0 )
return( 0 );
for ( i=1; i<=exponent; i++ )
product *= base;
return product;
}